<template>
	<view class="receive">
		<view class="nav">
			<u-tabs :list="list1" lineColor="#FF5B1A" :activeStyle="{color: '#FF5B1A'}" @click="change"
				:scrollable="false"></u-tabs>
		</view>
		<scroll-view scroll-y="true" class="main" @scrolltolower="lower()">
			<view class="list" v-for="(item,index) of list">
				<view class="t">
					<view class="title">{{item.name}}</view>
					<view class="status" v-if="type === 1">进行中</view>
					<view class="status" v-if="type === 0">审核中</view>
					<view class="status" v-if="type === 2">已下架</view>
					<view class="status" v-if="type === -1" @click="toast(item.note)">未通过,查看原因</view>
				</view>
				<view class="c">
					<view class="btn">{{item.taskcate.name}}</view>
					<view class="btn btn1">{{item.platform}}</view>
				</view>
				<view class="b">
					<view class="l">任务数量：<text class="num">{{item.acceptnum}}</text>/<text class="num">{{item.num}}</text>个</view>
					<view class="r">任务佣金：<text class="num">{{item.price}}</text> <text v-if="item.pay_type=='money'">元</text> <text v-if="item.pay_type=='score'">积分</text> </view>
				</view>
				<view class="btns" v-if="type === 1">
					<view class="btn stop" v-if="item.isstop === 0" @click="stop(item,1)">暂停</view>
					<view class="btn stop" v-if="item.isstop === 1" @click="stop(item,0)">开启</view>
					<view class="btn recharge" @click="top(item.id)">置顶</view>
					<view class="btn" @click="authTo(`pages/my/task/checklist?id=${item.id}`)">审核任务</view>
					<view class="btn stop" @click="refresh(item.id)">刷新</view>
					<view class="btn recharge" @click="addNum(item.id)">加量</view>
					<view class="btn" @click="addprice(item.id)">加价</view>
					<view class="btn" @click="down(item.id)">下架</view>
				</view>
			</view>
			<u-empty v-if="list.length === 0 && finish" mode="data" marginTop="100">
			</u-empty>
		</scroll-view>
		<u-modal :show="show" :title="`置顶1小时${info.top}元`" @confirm="confirm" @cancel="show = false"
			:showCancelButton="true">
			<view class="slot-content">
				<u--input placeholder="请输入置顶小时" border="surround" v-model="num"></u--input>
			</view>
		</u-modal>
		<u-modal :show="show1" :title="`刷新一次${info.refresh}元`" @confirm="confirm1" @cancel="show1 = false"
			:showCancelButton="true">

		</u-modal>
		<u-modal :show="show2" :title="`加量`" @confirm="confirm2" @cancel="show2 = false" :showCancelButton="true">
			<view class="slot-content">
				<u--input placeholder="请输入加量的数量" border="surround" v-model="num1"></u--input>
			</view>
		</u-modal>
		<u-modal :show="show3" :title="`加价`" @confirm="confirm3" @cancel="show3 = false" :showCancelButton="true">
			<view class="slot-content">
				<u--input placeholder="请输入加价的金额" border="surround" v-model="num2"></u--input>
			</view>
		</u-modal>
		<u-modal :show="show4" :title="note" @confirm="show4 = false" @cancel="show4 = false">
		
		</u-modal>
		<u-modal :show="show5"  title="确定要下架该任务吗" @confirm="confirm5" @cancel="show5 = false" :showCancelButton="true"></u-modal>
	</view>
</template>

<script>
	export default {
		data() {
			return {
				list1: [{
					name: '进行中',
					type: 1
				}, {
					name: '待审核',
					type: 0
				}, {
					name: '已下架',
					type: 2
				}, {
					name: '未通过',
					type: -1
				}],
				page: 1,
				finish: false,
				type: 1,
				list: [],
				show: false,
				show1: false,
				show2: false,
				show3: false,
				show4: false,
				show5: false,
				note: '',
				id: '',
				num: '',
				num1: '',
				num2: '',
				info: ''
			}
		},

		onLoad() {
			this.getList()
			this.getInfo()
		},
		methods: {
			confirm5() {
			
				this.show5 = false
				uni.$u.http.post('/usertask', {
					id: this.id,
					types: 'off'
				}).then(res => {
					if (res.code == 1) {
						uni.$u.toast(res.msg)
						this.reload()
					}
				}).catch((res) => {
				})
			},
			addNum(id) {
				this.id = id
				this.show2 = true
			},
			confirm2() {
				if(!uni.$u.test.digits(this.num1)){
					uni.$u.toast('请输入正确数量');
					return
				}
				this.show2 = false
				uni.$u.http.post('/usertask', {
					id: this.id,
					types: 'addnum',
					num: this.num1
				}).then(res => {
					if (res.code == 1) {
						uni.$u.toast(res.msg)
						this.reload()
					}
				}).catch((res) => {

				})
			},
			down(id) {
				this.id = id
				this.show5 = true
			},
			addprice(id) {
				this.id = id
				this.show3 = true
			},
			confirm3() {
				if(!uni.$u.test.amount(this.num2)){
					uni.$u.toast('请输入正确金额');
					return
				}
				this.show3 = false
				uni.$u.http.post('/usertask', {
					id: this.id,
					types: 'addprice',
					price: this.num2
				}).then(res => {
					if (res.code == 1) {
						uni.$u.toast(res.msg)
						this.reload()
					}
				}).catch((res) => {

				})
			},
			refresh(id) {
				this.id = id
				this.show1 = true
			},
			top(id) {
				this.id = id
				this.show = true
			},
			confirm1() {
				this.show1 = false
				uni.$u.http.post('/usertask', {
					id: this.id,
					types: 'refresh'
				}).then(res => {
					if (res.code == 1) {
						uni.$u.toast(res.msg)
					}
				}).catch((res) => {

				})
			},
			confirm() {
				this.show = false
				uni.$u.http.post('/usertask', {
					id: this.id,
					types: 'top',
					num: this.num
				}).then(res => {
					if (res.code == 1) {
						uni.$u.toast(res.msg)
					}
				}).catch((res) => {

				})
			},
			getInfo() {
				uni.$u.http.post('/usertask').then(res => {
					if (res.code == 1) {
						this.info = res.data
					}
				}).catch((res) => {

				})
			},
			stop(item, stop) {
				uni.$u.http.post('/usertask', {
					id: item.id,
					stop: stop,
					types: 'stop'
				}).then(res => {
					if (res.code == 1) {
						uni.$u.toast(res.msg)
						item.isstop = stop
					}
				}).catch((res) => {

				})
			},
			cancel(id) {
				uni.$u.http.post('/acceptcity', {
					id: id,
					types: 'cancel'
				}).then(res => {
					if (res.code == 1) {
						uni.$u.toast(res.msg)
					}
				}).catch((res) => {

				})
			},
			tel(mobile) {
				uni.makePhoneCall({
					phoneNumber: mobile
				});
			},
			toast(note) {
				this.note = note
				this.show4 = true
			},
			change(e) {
				console.log(e)
				this.type = e.type
				this.reload()
			},
			reload() {
				this.page = 1
				this.finish = false
				this.list = []
				this.getList()
			},
			lower() {
				this.page++
				this.getList()
			},
			getList() {
				if (this.finish) {
					return
				}
				uni.$u.http.post('/usertask', {
					page: this.page,
					type: this.type,
					types: 'list'
				}).then(res => {
					if (res.code == 1) {
						this.list = this.list.concat(res.data)
						if (res.data.length === 0) {
							this.finish = true
						}
					}
				}).catch((res) => {

				})
			}
		}
	}
</script>

<style lang="scss">
	.receive {
		height: 100vh;
		position: relative;
		background-color: #F6F6F6;

		.nav {
			display: flex;
			align-items: center;
			justify-content: center;
			flex-shrink: 0;
		}

		.main {
			position: absolute;
			left: 0;
			width: 100%;
			bottom: 0;
			top: 90rpx;
			padding-top: 20rpx;
			overflow: hidden;
		}

		.list {
			margin: 0 20rpx 20rpx;
			background-color: #fff;
			padding: 20rpx;
			border-radius: 20rpx;

			.t {
				display: flex;
				align-items: center;
				justify-content: space-between;

				.title {
					color: #191615;
					font-size: 36rpx;
					font-weight: bold;
				}

				.status {
					color: #428DFC;
					font-size: 30rpx;
				}

				.stop {
					color: #FF5B1A;
				}

				.end {
					color: #999999;
				}
			}

			.c {
				display: flex;
				align-items: center;
				margin: 20rpx 0;

				.btn {
					background: #FFFAE5;
					height: 36rpx;
					border-radius: 18rpx;
					padding: 0 10rpx;
					display: flex;
					align-items: center;
					justify-content: center;
					color: #FF8007;
					font-size: 24rpx;
					margin-right: 10rpx;
				}

				.btn1 {
					background-color: #E9F3FF;
					color: #428DFC;
				}
			}

			.b {
				display: flex;
				align-items: center;

				.l {
					color: #999999;
					font-size: 28rpx;
					margin-right: 20rpx;

					.num {
						color: #428DFC;
					}
				}

				.r {
					color: #999999;
					font-size: 28rpx;

					.num {
						color: #FF5B1A;
					}
				}
			}

			.btns {
				display: flex;
				flex-wrap: wrap;
				margin-top: 20rpx;

				.btn {
					width: 188rpx;
					height: 56rpx;
					box-sizing: border-box;
					border-radius: 10rpx;
					display: flex;
					align-items: center;
					justify-content: center;
					border: 1px solid #D5D5D5;
					margin: 0 20rpx 20rpx 0;
					color: #575859;
					font-size: 28rpx;
				}

				.stop {
					border: 1px solid #FF5B1A;
					color: #FF5B1A;
				}

				.recharge {
					border: 1px solid #428DFC;
					color: #428DFC;
				}
			}
		}
	}
</style>
